import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Main from '../views/Main.vue'
import Register from '../views/Register.vue'

import CommunityView from '../views/datacenter/CommunityView.vue'
import Cellshow from '../views/datacenter/Cellshow.vue'
import StallView from '../views/datacenter/StallView.vue'
import CarView from '../views/datacenter/CarView.vue'
import RoomView from '../views/datacenter/RoomView.vue'
import VisitorView from '../views/datacenter/VisitorView.vue'

import DeviceView from '../views/device/DeviceView.vue'
import NoticeView from '../views/property/NoticeView.vue'
import UserView from '../views/system/UserView.vue'
import FeeStandard from '../views/charge/FeeStandard.vue'
import FeeName from '../views/charge/FeeName.vue'
import MeterReading from '../views/charge/MeterReading.vue'
import Bill from '../views/charge/Bill.vue'
import DepartmentView from '../views/system/DepartmentView.vue'
import DeviceCheck from '../views/device/DeviceCheck.vue'
import DeviceCheckRecord from '../views/device/DeviceCheckRecord.vue'
import MaintainView from '../views/device/MaintainView.vue'
import DataAnalysis from '../views/device/DataAnalysis.vue'








Vue.use(VueRouter)
//  防止连续点击多次路由报错---写到路由.js中
let routerPush = VueRouter.prototype.push;
let routerReplace = VueRouter.prototype.replace;
// push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/register',
    name: 'register',
    component: Register
  },

  {
    path: '/',
    redirect: "/main"
  },
  {
    path: '/main',
    component: Main,
    children: [
      {
        path: '/',
        redirect: "/communityView"
      },
      {
        path: '/dataAnalysis',
        name: 'dataAnalysis',
        component: DataAnalysis
      },
      {
        path: '/maintainView',
        name: 'maintainView',
        component: MaintainView
      },
      {
        path: '/deviceCheckRecord',
        name: 'deviceCheckRecord',
        component: DeviceCheckRecord
      },
      {
        path: '/deviceCheck',
        name: 'deviceCheck',
        component: DeviceCheck
      },
      {
        path: '/departmentView',
        name: 'departmentView',
        component: DepartmentView
      },
      {
        path: '/userView',
        name: 'userView',
        component: UserView
      },
      {
        path: '/communityView',
        name: 'communityView',
        component: CommunityView
      },
      {
        path: '/cellshow/:value',
        name: 'cellshow',
        component: Cellshow
      },
      {
        path: '/roomView',
        name: 'roomView',
        component: RoomView
      },
      {
        path: '/stallView',
        name: 'stallView',
        component: StallView
      },
      {
        path: '/carView',
        name: 'carView',
        component: CarView
      },
      {
        path: '/visitorView',
        name: 'visitorView',
        component: VisitorView
      },
      {
        path: '/noticeView',
        name: 'noticeView',
        component: NoticeView
      },
      {
        path: '/feeStandard',
        name: '收费标准列表',
        component: FeeStandard
      },
      {
        path: '/feeName',
        name: '收费项目名列表',
        component: FeeName
      },
      {
        path: '/meterReading',
        name: '抄表录入',
        component: MeterReading
      },
      {
        path: '/bill',
        name: '账单列表',
        component: Bill,
      },
      {
        path: '/deviceView',
        name: 'deviceView',
        component: DeviceView
      },


    ]

  },


  // {
  //   path: '/about',
  //   name: 'about',
  // route level code-splitting
  // this generates a separate chunk (about.[hash].js) for this route
  // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router